package com.nacos.config.configuration;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;

import java.io.IOException;
import java.util.Properties;

/**
 * @author chn
 * @Feature: 获取配置中心的配置
 * @version 1.0
 * @data 2024/9/12 11:18
 */
public class getConfiguration {
    public static void main(String[] args) throws NacosException, IOException {
        Properties properties = new Properties();
        // 配置地址、用户名、密码
        properties.put("serverAddr", "localhost:8848");
        properties.put("username", "nacos");
        properties.put("password", "nacos");

        // 初始化配置中心的Nacos Java SDK
        ConfigService configService = NacosFactory.createConfigService(properties);

        // 初始化配置中心命名服务 Nacos Java SDK
        NamingService namingService = NacosFactory.createNamingService(properties);

        // 获取配置
        String config = configService.getConfig("user", "DEFAULT_GROUP", 5000);
        System.out.println(config);


    }
}
